package org.lanqiao.tjut.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.lanqiao.tjut.myutils.MyUtils;


public class EncodingCharsetFilter implements Filter {
	//FilterConfig 初始化成员变量
	FilterConfig myConf;
	

	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
			throws IOException, ServletException {
		//转发过滤处理逻辑
		//设置编码(；两种方式)
		//request.setCharacterEncoding("UTF-8");
		//response.setCharacterEncoding("UTF-8");
		
		request.setCharacterEncoding(myConf.getInitParameter("charSet"));
		response.setCharacterEncoding(myConf.getInitParameter("CharSet"));
		//输出日志
		MyUtils.logger_rootLogger.debug("编码格式为："+myConf.getInitParameter("charSet"));
		
		//将该请求转发给下一个过滤器或者Servlet
		//使用chain参数描述请求转发处理对象
		chain.doFilter(request, response);
		
	}
	
	@Override
	public void destroy() {
		// 销毁

	}


	@Override
	public void init(FilterConfig conf) throws ServletException {
		// 初始化
		myConf = conf;

	}

}
